#pragma once
#include"public_struct.h"
Node* connect(Node* root) {
	if (!root)return NULL;
	queue<Node*> q;
	q.push(root);
	while (!q.empty()) {
		int size = q.size();
		while (size-- > 0) {
			Node* temp = q.front();;
			q.pop();
			if (temp->left) { q.push(temp->left); }
			if (temp->right) { q.push(temp->right); }
			if (size) {
				temp->next = q.front();
			}
			else {
				temp->next = NULL;
			}

		}
	}
	return root;
}